﻿namespace X2OPC.Core.DA
{
    using System;
    using System.Runtime.InteropServices;

    [ComImport, ComVisible(true), Guid("0967B97B-36EF-423e-B6F8-6BFF1E40D39D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IOPCAsyncIO3
    {
        [PreserveSig]
        int Read([In] int dwCount, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] int[] phServer, [In] int dwTransactionID, out int pdwCancelID, out IntPtr ppErrors);
        
        [PreserveSig]
        int Write([In] int dwCount, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] int[] phServer, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] object[] pItemValues, [In] int dwTransactionID, out int pdwCancelID, out IntPtr ppErrors);
        
        [PreserveSig]
        int Refresh2([In, MarshalAs(UnmanagedType.U4)] OPCDataSource dwSource, [In] int dwTransactionID, out int pdwCancelID);
        
        [PreserveSig]
        int Cancel2([In] int dwCancelID);
        
        [PreserveSig]
        int SetEnable([In, MarshalAs(UnmanagedType.Bool)] bool bEnable);
        
        [PreserveSig]
        int GetEnable([MarshalAs(UnmanagedType.Bool)] out bool pbEnable);


        /// <summary>
        /// //从组对象内读取一个或多个项对象.结果通过IOPCDataCallback::OnReadComplete回调返回给客户。
        ///服务器将根据MaxAge参数做出项对象数据是从缓存还是设备获取的决定。
        ///如果缓存中的数据是MaxAge时间内的，那么项数据将从缓存中获取，否则服务器必须访问设备以获得
        ///项对象的数据。
        /// </summary>
        /// <param name="dwCount"></param>
        /// <param name="phServer"></param>
        /// <param name="pdwMaxAge"></param>
        /// <param name="dwTransactionID"></param>
        /// <param name="pdwCancelID"></param>
        /// <param name="ppErrors"></param>
        /// <returns></returns>
        [PreserveSig]
        int ReadMaxAge([In] int dwCount, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] int[] phServer, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] int[] pdwMaxAge, [In] int dwTransactionID, out int pdwCancelID, out IntPtr ppErrors);

        /// <summary>
        /// //对组对象内的一个或多个项对象进行写值、品质和时间邮戳操作。
        ///结果通过IOPCDataCallback::OnWriteComplete回调返回给客户。
        /// </summary>
        /// <param name="dwCount"></param>
        /// <param name="phServer"></param>
        /// <param name="pItemValues"></param>
        /// <param name="dwTransactionID"></param>
        /// <param name="pdwCancelID"></param>
        /// <param name="ppErrors"></param>
        /// <returns></returns>
        [PreserveSig]
        int WriteVQT([In] int dwCount, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] int[] phServer, [In] IntPtr pItemValues, [In] int dwTransactionID, out int pdwCancelID, out IntPtr ppErrors);

        /// <summary>
        ///对组对象内的所有激活项对象(无论它们是否有改变)强制调用
        ///IOPCDataCallback::OnDataChange回调,非激活的项对象不包括在回调中。
        ///MaxAge参数将决定数据是从缓存还是设备获取。
        /// </summary>
        /// <param name="dwMaxAge"></param>
        /// <param name="dwTransactionID"></param>
        /// <param name="pdwCancelID"></param>
        /// <returns></returns>
        [PreserveSig]
        int RefreshMaxAge([In] int dwMaxAge, [In] int dwTransactionID, out int pdwCancelID);
    }
}
